#include "../include/header.h"

bool flag = true;

long CharToInt(const char str[])
{
    if (NULL == str) {
        flag = false;
        return 0;
    }

    bool minus = false;
    const char *p = str;
    long sum = 0;

    if (*p == '-') {
        minus = true;
        p++;
    } else if (*p == '+') {
        minus = false;
        p++;
    }


    while (*p != '\0') {
        if (*p <= '9' && *p >= '0') {
            sum = sum * 10 + *p - 48;
            p++;
        } else {
            flag = false;
            return 0;
            break;
        }
    }

    if (minus) {
        sum = 0 - sum;
    }

    return sum;
}


void TestForTwenty()
{
    char * p = "+12349999999";
    long sum = CharToInt(p);
    if (flag)
        cout << sum << endl;
    else
        cout << "There are some errors in the string ,please confirm that!" << endl;
}
